package com.power.leopard.remote.http;

import org.mortbay.jetty.Server;

import com.power.leopard.common.util.NetUtils;
import com.power.leopard.constants.Constants;
import com.power.leopard.remote.ProviderConfig;
import com.power.leopard.remote.ServerConfig;
import com.power.leopard.remote.provider.AbstractServer;

public class JettyHttpServer extends AbstractServer {

	private volatile boolean started = false;

	private Server server;
	private int port;

	public JettyHttpServer() {

	}

	public boolean isStarted() {
		return started;
	}

	public boolean support(ServerConfig serverConfig) {
		return serverConfig.getProtocol().equals(getProtocol());
	}

	public void start(ServerConfig serverConfig) {
		// TODO Auto-generated method stub

	}

	public void stop() {
		// TODO Auto-generated method stub

	}

	public ServerConfig getServerConfig() {
		// TODO Auto-generated method stub
		return null;
	}

	public int getPort() {
		// TODO Auto-generated method stub
		return 0;
	}

	public <T> void addService(ProviderConfig<T> providerConfig) {
		// TODO Auto-generated method stub

	}

	private Server newServer(ServerConfig serverConfig) {
		port = NetUtils.getAvailablePort(serverConfig.getHttpPort());
		return null;
	}

	@Override
	public void doStart(ServerConfig serverConfig) {
		int retries = 0;
		while (!started) {

		}
	}

	@Override
	public void doStop() {
		// TODO Auto-generated method stub

	}

	public String getProtocol() {
		return Constants.PROTOCOL_HTTP;
	}

	// private Server newServer(ServerConfig serverConfig) {
	// int availablePort =
	// NetUtils.getAvailablePort(serverConfig.getHttpPort());
	// this.port = availablePort;
	// }
}
